<?php
require_once dirname(__FILE__) . '/../../../incls/php/dbutils.class.php';
require_once dirname(__FILE__) . '/../../../incls/php/miscutils.class.php';
require_once dirname(__FILE__) . '/../../../incls/php/config.php';
session_name(SESSION);
session_start();

$myPdo = DbUtils::createPdoInst();
$page_id = MiscUtils::getParam('i', 0);

$SIZE = 999;
$page = MiscUtils::getParam('pg', 1);
$cond_vals = new stdClass(); 
$cond_vals->c = 't1.status = :v1';
$cond_vals->v = array(':v1' => 1);
$opt = new stdClass();
$opt->select_expr = 't.*, t1.name AS _name, t1.track_id AS _track_id, t1.price AS _price, t1.status AS _status';
$opt->join_expr = 'LEFT JOIN ' . TABLE_NAME_PREFIX_PLUGIN . 'ecom_product AS t1 ON t.product_id = t1.id';
$recoms = DbUtils::get($myPdo,  TABLE_NAME_PREFIX_PLUGIN . 'admin_hm_recom', $cond_vals, 't.order_number', 'ASC', $page, $SIZE, $opt)->d;
foreach ($recoms as $recom) {
  $recom->_img = 'images/no_image.gif';
  $cond_vals = new stdClass(); 
  $cond_vals->c = 't.product_track_id = :v1 AND is_default = 0';
  $cond_vals->v = array(':v1' => $recom->_track_id);
  $tmp = DbUtils::get($myPdo, TABLE_NAME_PREFIX_PLUGIN . 'ecom_product_img', $cond_vals, NULL, NULL, NULL, NULL, NULL)->d;
  if (count($tmp) > 0) {
    if (file_exists($tmp[0]->file)) {
      $recom->_img = $tmp[0]->file;
    }
    
  }
  
  $recom->_prc = $recom->_price;
  if (isset($_SESSION['index' . USER]) && $_SESSION['index' . USER]->id) {
    $cond_vals = new stdClass();
    $cond_vals->c = 't.product_track_id = :v1 AND t.member_id = :v2';
    $cond_vals->v = array(':v1' => $recom->_track_id, ':v2' => $_SESSION['index' . USER]->member_id);
    $tmp = DbUtils::get($myPdo,  TABLE_NAME_PREFIX_PLUGIN . 'ecom_product_member_price', $cond_vals, NULL, NULL, NULL, NULL, NULL)->d;
    if (count($tmp) > 0) {
      $recom->_prc = $tmp[0]->price;
    }
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<style>
* {
  font-family: Trebuchet MS;
  font-size: 12px;
  padding: 0;
  margin: 0;
}
td.clr {
  background: #633966;
  width: 20px;
  height: 30px;
}
td.wrd {
  font-family: Lucida Sans Unicode;
  font-weight: bold;
  margin-left: 10px;
  margin-bottom: 15px;
  font-size: 14px;
  padding-left: 5px;
}
.prdt {
  border: 1px solid #ddd;
  padding: 5px 10px;
  text-align: center;
  margin-left: 6px;
  margin-bottom: 10px;
  width: 140px;
  height: 140px;
  display: inline-block;
  *display: inline;
  zoom: 1;
}
.prdt img {
  width: 120px;
  height: 96px;
  cursor: pointer;
}
</style>
</head>
<body>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<table cellspacing=0 cellpadding=0>
  <tr>
    <td class="clr">&nbsp;</td>
    <td class="wrd">Recommended Products</td>
  </tr>
</table>
<div>&nbsp;</div>
<?php foreach ($recoms as $recom) { ?>
<div class="prdt">
  <div><b><?php echo MiscUtils::getShortName($recom->_name, 10); ?></b></div>
  <img src="<?php echo $recom->_img; ?>" onclick="window.open('http://<?php echo URL . '?i=' . HOME_PROD_ID . '&id=' . $recom->_track_id; ?>')"></img>
  <div>$<?php echo $recom->_prc; ?></div>
</div>
<?php } ?>
<div>&nbsp;</div>
<div>&nbsp;</div>
</body>
</html>